package frontend.model.admin;

import backend.model.admin.Employee;
import backend.model.admin.Foreman;
import backend.model.admin.Team;
import frontend.model.base.UIModel;

import java.util.HashSet;
import java.util.Set;

public class TeamUIModel implements UIModel<Team> {

    private String name;
    private boolean isExternal;
    private boolean isActive;
    private Foreman foreman;
    private Set<Employee> employees = new HashSet<Employee>();

    private Team team;

    public TeamUIModel() {
        team = new Team();
        isActive = true;
    }

    public TeamUIModel(Team team) {
        this.team = team;
        populateFieldsFromDBModel();
    }

    public Set<Employee> getEmployees() {
        return this.employees;
    }

    public void setEmployees(Set<Employee> employees) {
        team.setEmployees(employees);
        this.employees = employees;
    }

    @Override
    public void populateFieldsFromDBModel() {
        name = team.getName();
        foreman = team.getForeman();
        employees = team.getEmployees();
        isExternal = team.getIsExternal();
        isActive = team.getIsActive();
    }

    @Override
    public void populateDBModelFromFields() {
        team.setName(name);
        team.setForeman(foreman);
        team.setIsExternal(isExternal);
        team.setIsActive(isActive);
        for (Employee employee : employees) {
            employee.setTeam(team);
        }
    }

    public String getName() {
        return name;
    }

    public Foreman getForeman() {
        return foreman;
    }

    public boolean getIsExternal() {
        return isExternal;
    }

    public boolean getIsActive() {
        return isActive;
    }

    @Override
    public Team getDBModel() {
        return team;
    }
}
